package cn.wzc.crystal.platform.golbal;

import cn.wzc.crystal.platform.support.AbstractEntity;
import org.springframework.data.relational.core.conversion.MutableAggregateChange;
import org.springframework.data.relational.core.mapping.event.BeforeSaveCallback;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;

/**
 * 系统实体对象
 */
@Component
public class GlobalEntityHandler implements BeforeSaveCallback<AbstractEntity> {

	@Override
	@NonNull
	public AbstractEntity onBeforeSave(@Nonnull AbstractEntity aggregate, @Nonnull MutableAggregateChange<AbstractEntity> aggregateChange) {

		// 没有ID 表示是新建
		if (null == aggregate.getId()) {
			aggregate.setIsDeleted(0);
		}

		return aggregate;
	}
}
